package model

import (
	"smart-health-platforms/config"
	"time"
)

type BargainHelp struct {
	Id                uint32    `gorm:"column:id;type:int UNSIGNED;primaryKey;not null;" json:"id"`
	BargainActivityId int32     `gorm:"column:bargain_activity_id;type:int;default:NULL;" json:"bargain_activity_id"`
	UserId            int32     `gorm:"column:user_id;type:int;default:NULL;" json:"user_id"`
	Price             float64   `gorm:"column:price;type:decimal(10, 2);default:NULL;" json:"price"`
	Status            int32     `gorm:"column:status;type:int;comment:1-帮砍中2-已砍完;default:NULL;" json:"status"` // 1-帮砍中2-已砍完
	CreatedAt         time.Time `gorm:"column:created_at;type:datetime(3);default:CURRENT_TIMESTAMP(3);" json:"created_at"`
}

func (b *BargainHelp) TableName() string {
	return "bargain_help"
}
func (b *BargainHelp) AddBargainHelp() error {
	return config.DB.Create(&b).Error
}
func (b *BargainHelp) UpdateBargainHelp() error {
	return config.DB.Model(&b).Updates(&b).Error
}
func (b *BargainHelp) DeletedBargainHelp() error {
	return config.DB.Model(&b).Delete(&b).Error
}
func (b *BargainHelp) BargainHelpList() (bae []BargainHelp, err error) {
	err = config.DB.Where("bargain_activity_id = ?", b.BargainActivityId).Find(&bae).Error
	return
}
